package com.auto.finance.auth.collect.support;

import com.auto.finance.auth.collect.annotations.ApiInclude;
import com.auto.finance.auth.collect.beans.ApiInfo;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author tianye
 */
public interface RequestPathHandle {

    /**
     * 是否支持该注解的处理
     *
     * @param annotation
     * @return
     */
    boolean support(Annotation annotation);

    /**
     * 处理注解信息
     *
     * @param prefix     path前缀，一般情况下指controller类上的RequestMapping
     * @param annotation
     * @param apiInclude
     * @return
     */
    List<ApiInfo> handle(String[] prefix, Annotation annotation, ApiInclude apiInclude);


    /**
     * 拼接完整path
     *
     * @param prefix
     * @param paths
     * @return
     */
    default List<String> build(String[] prefix, String[] paths) {
        String p = prefix.length > 0 ? prefix[0] : "";
        String s = paths.length > 0 ? paths[0] : "";
        if (p.length() == 0 && s.length() == 0) {
            return Collections.emptyList();
        }
        return Arrays.asList(p + s);
    }

}
